import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from base_class.base_utils import spend_time
from aws_model.aws_s3 import Operation_aws_s3

aws_s3 = Operation_aws_s3()


@spend_time("删除文件耗时：")
def delete_data(table_name: str, date, material=None):
    table = table_name.split(".")[-1]
    if 'kyd' in table:
        path = f'crm/partitions/p_date={date}'
    else:
        path = f'{table}/p_date={date}/material={material}'

    if path:
        file_list = aws_s3.list_object('ods', path)
        if file_list:
            for file in file_list:
                if file:
                    filepath = file.get('path')
                    aws_s3.empty_object('ods', filepath)
